package com.sd.mapper;

import com.sd.domain.ImCollect;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * @author yexinming
 * @date 2020/3/12
 **/
@Mapper
public interface ImCollectMapper {
    /**
     * 根据坐席id查询列表
     * @param agentId
     * @return
     */
    @Select("select " +
                "id," +
                "agent_id," +
                "user_id," +
                "type," +
                "source," +
                "content," +
                "file_path," +
                "gmt_create," +
                "gmt_modified " +
            "from im_collect " +
            "where agent_id = #{agentId}")
    @Results({
            @Result(property = "id",column = "id",id=true),
            @Result(property = "agentId",column = "agent_id"),
            @Result(property = "userId",column = "user_id"),
            @Result(property = "type",column = "type"),
            @Result(property = "source",column = "source"),
            @Result(property = "content",column = "content"),
            @Result(property = "filePath",column = "file_path"),
            @Result(property = "gmtCreate",column = "gmt_create"),
            @Result(property = "gmtModified",column = "gmt_modified")
    })
    List<ImCollect> listByAgentId(@Param("agentId") String agentId);
    /**
     * 保存
     * @param collect 收藏对象
     */
    @Insert("insert into im_collect(" +
                "agent_id," +
                "user_id," +
                "type," +
                "source," +
                "content," +
                "file_path," +
                "gmt_create," +
                "gmt_modified" +
            ") values(" +
                "#{agentId}," +
                "#{userId}," +
                "#{type}," +
                "#{source}," +
                "#{content}," +
                "#{filePath}," +
                "#{gmtCreate}," +
                "#{gmtModified}" +
            ")")
    @Options(keyColumn = "id",keyProperty = "id",useGeneratedKeys = true)
    void save(ImCollect collect);
    /**
     * 根据主键获取对象
     * @param id 主键
     * @return
     */
    @Select("select " +
            "user_name," +
            "phone," +
            "parent_id," +
            "parent_phone," +
            "parent_name," +
            "is_valid," +
            "remark," +
            "create_time," +
            "update_time," +
            "partnerid" +
            "from im_collect " +
            "where id = #{id}")
    @Results({
            @Result(property = "id",column = "id",id=true),
            @Result(property = "agentId",column = "agent_id"),
            @Result(property = "userId",column = "user_id"),
            @Result(property = "type",column = "type"),
            @Result(property = "source",column = "source"),
            @Result(property = "content",column = "content"),
            @Result(property = "filePath",column = "file_path"),
            @Result(property = "gmtCreate",column = "gmt_create"),
            @Result(property = "gmtModified",column = "gmt_modified")
    })
    ImCollect getById(@Param("id") Long id);
}
